﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace _3D_FileExplorer
{
    class BoundingCube
    {
        public VertexPositionColorTexture[] boxa = new VertexPositionColorTexture[8];
        public VertexPositionColorTexture[] boxb = new VertexPositionColorTexture[8];
        float xMin, xMax;
        float yMin, yMax;
        float zMin, zMax;
        public Matrix rotation = Matrix.Identity;
        public Matrix translation = Matrix.Identity;
        Color color;

        public BoundingCube(float xMin, float xMax, float yMin, float yMax, float zMin, float zMax, Matrix translation, Color color)
        {
            this.xMin = xMin;
            this.xMax = xMax;
            this.yMin = yMin;
            this.yMax = yMax;
            this.zMin = zMin;
            this.zMax = zMax;
            this.translation = translation;
            this.color = color;
            CreateBox();
        }
         private void CreateBox(){

             boxa[0].Position = new Vector3(xMax, yMin, zMax);
             boxa[1].Position = new Vector3(xMax, yMax, zMax);
             boxa[2].Position = new Vector3(xMax, yMax, zMin);
             boxa[3].Position = new Vector3(xMax, yMin, zMin);
             boxa[4].Position = new Vector3(xMax, yMin, zMax);
             boxa[5].Position = new Vector3(xMin, yMin, zMax);
             boxa[6].Position = new Vector3(xMin, yMax, zMax);
             boxa[7].Position = new Vector3(xMax, yMax, zMax);

             boxb[0].Position = new Vector3(xMin, yMin, zMin);
             boxb[1].Position = new Vector3(xMin, yMax, zMin);
             boxb[2].Position = new Vector3(xMin, yMax, zMax);
             boxb[3].Position = new Vector3(xMin, yMin, zMax);
             boxb[4].Position = new Vector3(xMin, yMin, zMin);
             boxb[5].Position = new Vector3(xMax, yMin, zMin);
             boxb[6].Position = new Vector3(xMax, yMax, zMin);
             boxb[7].Position = new Vector3(xMin, yMax, zMin);

             int i;
             for (i = 0; i < boxa.Length; i++)
             {
                 boxa[i].Color = color;
                 boxb[i].Color = color;
             }

         }

         public virtual void Draw(BasicEffect effect, Camera camera, GraphicsDevice Device)
         {
             effect.World = rotation * translation;
             effect.View = camera.view;
             effect.Projection = camera.projection;
             effect.VertexColorEnabled = true;
             effect.Begin();
             foreach (EffectPass pass in effect.CurrentTechnique.Passes)
             {
                 pass.Begin();
                 Device.DrawUserPrimitives<VertexPositionColorTexture>
                 (PrimitiveType.LineStrip, boxa, 0, 7);
                 Device.DrawUserPrimitives<VertexPositionColorTexture>
                 (PrimitiveType.LineStrip, boxb, 0, 7);
                 pass.End();
             }

             effect.End();
         }




    }
}
